import { ActionTree, Module, MutationTree } from 'vuex'
import { RootState } from '../root-state'
import Cookies from 'js-cookie'

export interface appTypes {
    sidebar: {
        opened: boolean;
        withoutAnimation: boolean;
    }
    device: 'desktop'
}

const state: appTypes = {
    sidebar: {
        opened: Cookies.get('sidebarStatus') ? !!Cookies.get('sidebarStatus') : true,
        withoutAnimation: false
    },
    device: 'desktop'
}

export const CHANGE_SETTING = 'CHANGE_SETTING'

const mutations: MutationTree<appTypes> = {
    [CHANGE_SETTING](state: appTypes, data: appTypes) {
        state = data
    }
}

const action: ActionTree<appTypes, RootState> = {
    [CHANGE_SETTING]({ commit }, data: appTypes) {
        commit(CHANGE_SETTING, data)
    }
}
export const setting: Module<appTypes, RootState> = {
    namespaced: true,
    state: state,
    mutations,
    actions:action
}
